package com.lk.lkappearance.service.impl;

import com.lk.lkappearance.common.AbstractBaseService;
import com.lk.lkappearance.mapper.DeviceMapper;
import com.lk.lkappearance.model.Device;
import com.lk.lkappearance.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DeviceServiceImpl extends AbstractBaseService implements DeviceService {

    @Autowired
    private DeviceMapper deviceMapper;

    /**
     *
     * @param device
     * @return
     */
    @Override
    public Map<String, Object> add(Device device) {
        try {
            deviceMapper.insertSelective(device);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     *
     * @param device
     * @return
     */
    @Override
    public Map<String, Object> modify(Device device) {
        try {
            deviceMapper.updateByPrimaryKeySelective(device);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     *
     * @param deviceId
     * @return
     */
    @Override
    public Map<String,Object> selectByPrimaryKey(String deviceId) {
        try {
            deviceMapper.selectByPrimaryKey(deviceId);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     *
     * @param deviceId
     * @return
     */
    @Override
    public Map<String, Object> delete(String deviceId) {
        try {
            deviceMapper.deleteByPrimaryKey(deviceId);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    @Override
    public Map<String, Object> getList(Device device) {
        Map<String,Object> result=new HashMap<>();
        try {
            List<Device> list = deviceMapper.getList(device);
            result.put("list",list);
        }catch (Exception e){
            e.printStackTrace();
        }
        return success().setData(result).getResult();
    }

    @Override
    public Map<String, Object> getListExcel(Device device) {
        Map<String,Object> result=new HashMap<>();
        try {
            List<Device> list = deviceMapper.getListExcel(device);
            result.put("list",list);
        }catch (Exception e){
            e.printStackTrace();
        }
        return success().setData(result).getResult();
    }

    @Override
    public Map<String, Object> insertListExcel(List<Device> deviceList) {
        try {
            for (Device device:deviceList) {
                deviceMapper.insertSelective(device);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }
}
